<form action="{:sysuri()}" autocomplete="off" class="layui-form layui-form-pane form-search" method="get" onsubmit="return false">

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">会员用户</label>
        <label class="layui-input-inline">
            <input class="layui-input" name="username" placeholder="请输入手机或昵称" value="{$get.username|default=''}">
        </label>
    </div>

    <!--{notempty name='upgrades'}-->
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">用户等级</label>
        <div class="layui-input-inline">
            <select class="layui-select" name="vip_code">
                <option value="">-- 全部 --</option>
                {foreach $upgrades as $upgrade}{if input('vip_code') eq $upgrade.number.''}
                <option selected value="{$upgrade.number|default=0}">[ VIP{$upgrade.number|default='0'} ] {$upgrade.name|default=''}</option>
                {else}
                <option value="{$upgrade.number|default=0}">[ VIP{$upgrade.number|default='0'} ] {$upgrade.name|default=''}</option>
                {/if}{/foreach}
            </select>
        </div>
    </div>
    <!--{/notempty}-->

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">代理用户</label>
        <label class="layui-input-inline">
            <input class="layui-input" name="from_keys" placeholder="请输入手机或昵称" value="{$get.from_keys|default=''}">
        </label>
    </div>

    <!--{notempty name='upgrades'}-->
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">代理等级</label>
        <div class="layui-input-inline">
            <select class="layui-select" name="from_vipcode">
                <option value="">-- 全部 --</option>
                {foreach $upgrades as $upgrade}{if input('from_vipcode') eq $upgrade.number.''}
                <option selected value="{$upgrade.number|default=0}">[ VIP{$upgrade.number|default='0'} ] {$upgrade.name|default=''}</option>
                {else}
                <option value="{$upgrade.number|default=0}">[ VIP{$upgrade.number|default='0'} ] {$upgrade.name|default=''}</option>
                {/if}{/foreach}
            </select>
        </div>
    </div>
    <!--{/notempty}-->

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">使用状态</label>
        <div class="layui-input-inline">
            <select class="layui-select" name="status">
                <option value="">-- 全部 --</option>
                {foreach ['已冻结的用户', '已激活的用户'] as $k=>$v}
                {if $k.'' eq input('status')}
                <option selected value="{$k}">{$v}</option>
                {else}
                <option value="{$k}">{$v}</option>
                {/if}{/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">注册时间</label>
        <div class="layui-input-inline">
            <input class="layui-input" data-date-range name="create_at" placeholder="请选择注册时间" value="{$get.create_at|default=''}">
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
        <button class="layui-btn layui-btn-primary" data-form-export="{:url('index')}?type={$type}" type="button">
            <i class="layui-icon layui-icon-export"></i> 导 出
        </button>
    </div>
</form>

<script>
    require(['excel'], function (excel) {
        excel.bind(function (data) {

            // 设置表格内容
            data.forEach(function (item, index) {
                data[index] = [
                    {v: item.id, t: 'n'},
                    item.openid1 || '-',
                    item.openid2 || '-',
                    item.username || item.nickname || '',
                    item.vip_name || '-',
                    {v: item.balance_total || '0.00', t: 'n'},
                    {v: item.balance_used || '0.00', t: 'n'},
                    {v: item.rebate_total || '0.00', t: 'n'},
                    {v: item.rebate_lock || '0.00', t: 'n'},
                    {v: item.rebate_used || '0.00', t: 'n'},
                    item.create_at || '',
                ];
            });

            // 设置表头内容
            data.unshift(['ID', '小程序', '公众号', '用户姓名', '用户等级', '累计充值余额', '已使用余额', '累计返利金额', '锁定返利金额', '已提现金额', '注册时间']);

            // 自动计算列序号
            var lastCol = layui.excel.numToTitle((function (count, idx) {
                for (idx in data[0]) count++;
                return count;
            })(0));

            // 设置表头样式
            layui.excel.setExportCellStyle(data, 'A1:' + lastCol + '1', {
                s: {
                    font: {sz: 12, bold: true, color: {rgb: "FFFFFF"}, name: '微软雅黑', shadow: true},
                    fill: {bgColor: {indexed: 64}, fgColor: {rgb: "5FB878"}},
                    alignment: {vertical: 'center', horizontal: 'center'}
                }
            });

            // 设置内容样式
            var style1 = {
                font: {sz: 10, shadow: true, name: '微软雅黑'},
                fill: {bgColor: {indexed: 64}, fgColor: {rgb: "EAEAEA"}},
                alignment: {vertical: 'center', horizontal: 'center'}
            }, style2 = {
                font: {sz: 10, shadow: true, name: '微软雅黑'},
                fill: {bgColor: {indexed: 64}, fgColor: {rgb: "FFFFFF"}},
                alignment: {vertical: 'center', horizontal: 'center'}
            };
            layui.excel.setExportCellStyle(data, 'A2:' + lastCol + data.length, {s: style1}, function (rawCell, newCell, row, config, curRow) {
                /* 判断并转换单元格数据为对象，以便初始化样式 */
                typeof rawCell !== 'object' && (rawCell = {v: rawCell});
                rawCell.s = Object.assign({}, style2, rawCell.s || {});
                return (curRow % 2 === 0) ? newCell : rawCell;
            });

            // 设置表格行宽高，需要设置最后的行或列宽高，否则部分不生效 ？？？
            var rowsC = {1: 33}, colsC = {A: 60, B: 80, C: 80, E: 80};
            rowsC[data.length] = 28, colsC[lastCol] = 160;
            this.options.extend = {
                '!rows': layui.excel.makeRowConfig(rowsC, 28), // 设置每行高度，默认 33
                '!cols': layui.excel.makeColConfig(colsC, 99), // 设置每行宽度，默认 99
            };

            return data;
        }, '会员用户数据');
    });
</script>
